package JZOffer;

import java.util.Arrays;

// https://leetcode.cn/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/?envType=study-plan&id=lcof&plan=lcof&plan_progress=xxj1ozje
// 调整数组顺序使奇数位于偶数前面
public class Day013_1 {
    public static int[] exchange(int[] nums) {
        int l = 0;
        int r = nums.length-1;

        while (l < r) {
            if (nums[l] % 2 != 0) {
                l++;
            }
            if (nums[r] % 2 == 0) {
                r--;
            }
            if (l < r && nums[l] % 2 == 0 && nums[r] % 2 != 0) {
                int tmp = nums[l];
                nums[l] = nums[r];
                nums[r] = tmp;
            }
        }
        return nums;
    }


    public static void main(String[] args) {
        int[] arr = {1,2,3,4};
        System.out.println(Arrays.toString(exchange(arr)));
    }
}
